package cn.itcast.bos.web.base.action;

import domain.base.Standard;
import cn.itcast.bos.service.base.StandardService;
import org.apache.struts2.convention.annotation.*;
import org.springframework.context.annotation.Scope;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Controller;

/**
 * 整合struts2-json-plugin插件
 * 继承json-default
 * 使result可以传回json数据到前台
 */
@ParentPackage("json-default")
@Namespace("/")
@Controller
@Actions
@Scope("prototype")
public class StandardAction extends BaseAction<Standard,StandardService>{


    //建立保存Action
    @Action(value = "standard_save",results = {@Result(name = "success",location = "/pages/base/standard.html",type = "redirect")})
    public String save(){
        service.save(model);
        return SUCCESS;
    }
    //分页查询
    //设置回传值为json
    @Action(value = "standard_pageQuery",results = {@Result(name = "success",type = "json")})
    public String pageQuery(){
        //PageRequest提供的page信息是从0开始的,所以导进去时需要-1
        Pageable pageable = new PageRequest(page-1,rows);
        //将返回的分页数据数据封装进实体迭代器中
        Page<Standard> pageData = service.findPageData(pageable);
        //通过BaseAction实现封装分页进入值栈
        pushPageDataToValueStack(pageData);
        return SUCCESS;
    }

}
